//
//  ClassTwoDataViewController.m
//  Feel_at_home
//
//  Created by dlios on 15/9/29.
//  Copyright © 2015年 Feel_at_home. All rights reserved.
//

#import "ClassTwoDataViewController.h"
#import "WidthAndHeight.pch"
#import "HTTPTOOL.h"
#import "ClassModel.h"
#import "ClassDataVewCell.h"

@interface ClassTwoDataViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *URLArr;

@end

@implementation ClassTwoDataViewController

// 自定义
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.URLArr = [NSMutableArray array];
        self.title = @"分类详情";
    }
    return self;
}

// 网络解析
- (void)didHandle
{
    
    [HTTPTOOL GETWithURL:self.URL body:nil httpHead:nil responseStyle:JSON success:^(id result) {
        
        NSArray *arr = [[result objectForKey:@"data"] objectForKey:@"items"];
        for (NSDictionary *dic in arr) {
            ClassModel *Model = [[ClassModel alloc]init];
            [Model setValuesForKeysWithDictionary:dic];
            [self.URLArr addObject:Model];
        }
        [self.tableView reloadData];
        
    } fail:^(NSError *error) {
        NSLog(@"%@", error);
        
    }];

}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self didHandle];
    [self tableViewSubViews];
    
}

// tableView
- (void)tableViewSubViews
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, VCWIDTH, VCHEIGH - 64) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor clearColor];
}

// tableView协议
// 区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
// 行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.URLArr.count;
}
// heigth
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}
// cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassDataVewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"classDataViewCell"];
    if (!cell) {
        cell = [[ClassDataVewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"classDataViewCell"];
    }
    ClassModel *classM = [self.URLArr objectAtIndex:indexPath.row];
    cell.classM = classM;
    
    return cell;
}

// cell点击跳转方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
